//
//  CourseDetailsViewController.m
//  BeanSproutEDU
//
//  Created by douya on 15/1/8.
//  Copyright (c) 2015年 douya. All rights reserved.
//

#import "CourseDetailsViewController.h"
#import "CourseTableCell.h"
#import "EvaluationTableCell.h"
#import "DouyaPlayerViewController.h"
#import "VideoModel.h"
#import "PlayerViewController.h"
#import "Header.h"
@interface CourseDetailsViewController ()

@end

@implementation CourseDetailsViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"CourseDetailsView"];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"CourseDetailsView"];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    count=0;
    // Do any additional setup after loading the view from its nib.
    
    self.title=@"课程详细";
    self.navigationController.navigationBar.titleTextAttributes=[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
    
    UIBarButtonItem *shareItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"shareItem2.png"] style:UIBarButtonItemStyleDone target:self action:@selector(shareBtnClick)];
    self.navigationItem.rightBarButtonItem=shareItem;
    
    //课程界面的表
    self.courseViewTableView.delegate=self;
    self.courseViewTableView.dataSource=self;
    
    //评价界面的表
    self.evlauationViewTabelView.delegate=self;
    self.evlauationViewTabelView.dataSource=self;

 
    
}


//课程界面与评价界面之间的切换
- (IBAction)segmentControl:(UISegmentedControl *)sender
{
    switch (sender.selectedSegmentIndex)
    {
        case 0:
        {
            self.courseView.alpha=1;
            self.evaluationView.alpha=0;
        }
            break;
        case 1:
        {
            self.courseView.alpha=0;
            self.evaluationView.alpha=1;
        }
            break;
            
        default:
            break;
    }
}

-(void)shareBtnClick
{
    NSLog(@"share");
}
#pragma mark- UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView.tag==10)
    {
        return 20;
    }
    else
    {
        return 3;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID=@"cell1";
    if (tableView.tag==10)//获取课程的单元格
    {
        CourseTableCell *cell=(CourseTableCell *)[tableView dequeueReusableCellWithIdentifier:ID];
        if (!cell)
        {
            NSArray *array=[[NSBundle mainBundle] loadNibNamed:@"CourseTableCell" owner:nil options:nil];
            cell=array[0];
        }
        cell.cell1_titleLabel.text=[NSString stringWithFormat:@"拉丁舞起源%d",indexPath.row+1];
        return cell;
    }
    else//获取评价的单元格
    {
        EvaluationTableCell *cell=(EvaluationTableCell *)[tableView dequeueReusableCellWithIdentifier:ID];
        if (!cell)
        {
            NSArray *array=[[NSBundle mainBundle] loadNibNamed:@"EvaluationTableCell" owner:nil options:nil];
            cell=array[0];
        }
        return cell;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView.tag==10)
    {
        _videoArray=[NSMutableArray array];
        for (int i=1; i<7; i++)
        {
            NSString *videoUrl=[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%d",i] ofType:@"mp4"];
            NSURL *videoURL=[NSURL fileURLWithPath:videoUrl];
            [_videoArray addObject:videoURL];
        }
        _mediaPlayURL=_videoArray[0];

        //通过子类去播放 子类可以控制界面的方向
        _viewPlayer=[[DouyaPlayerViewController alloc] initWithContentURL:_mediaPlayURL];
        _viewPlayer.videoArray=_videoArray;
        _player=[_viewPlayer moviePlayer];
        
        _player.controlStyle=MPMovieControlStyleFullscreen;
        
        [self presentMoviePlayerViewControllerAnimated:_viewPlayer];
        
    }
}


-(BOOL)shouldAutorotate
{
    return NO;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end
